package databaseVersionControl.domain.dialect.oracle;

import databaseVersionControl.domain.db.DataType;
import databaseVersionControl.domain.dialect.Dialect;

public class OracleDialect extends Dialect {

	@Override
	protected void setup() {
		registerColumnType(DataType.STRING, "VARCHAR2");
		registerColumnType(DataType.CHAR, "CHAR");
		registerColumnType(DataType.INTEGER, "CHAR");
		registerColumnType(DataType.LONG, "NUMBER");
		registerColumnType(DataType.FLOAT, "BINARY_FLOAT");
		registerColumnType(DataType.DOUBLE, "BINARY_DOUBLE");
		registerColumnType(DataType.DATE, "DATE");
		registerColumnType(DataType.TIMESTAMP, "TIMESTAMP");
	}

	@Override
	public String getNextSequenceValue(String sequenceName) {
		return String.format("SELECT %s.NEXTVAL FROM dual;", sequenceName);
	}

	@Override
	public String checkExistTable(String name) {
		return String.format("select TABLE_NAME from ALL_TABLES where TABLE_NAME = upper('%s')", name);
	}

	@Override
	public String checkExistSequence(String sequenceName) {
		return String.format("SELECT SEQUENCE_NAME FROM ALL_SEQUENCE WHERE SEQUENCE_NAME = UPPER('%s')", sequenceName);
	}

}